package com.example.demo.mapper;

import com.example.demo.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author Mr.Yang
 * @since 2024-05-31
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    //根据昵称查找用户
    @Select("SELECT nickname FROM  user WHERE user_id =#{userId}")
    User findNicknameByUserId(@Param("userId") Integer userId);

    /**
     * 根据用户id查询用户
     * @param userId
     * @return
     */
    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User selectByUserId(Integer userId);
    /**
     *查询用户的list集合
     */
    @Select("<script>" +
            "select * from user" +
            "        <choose>" +
            "            <when test='sidx != null and sidx.trim() != \"\"'>" +
            "                order by ${sidx} ${order}" +
            "            </when>" +
            "            <otherwise>" +
            "                order by id desc" +
            "            </otherwise>" +
            "        </choose>" +
            "        <if test='offset != null and limit != null'>" +
            "            limit #{offset}, #{limit}\n" +
            "        </if>" +
            "</script>")
    List<User> queryList(Map<String, Object> map);
    @Select("select * from user where id = #{value}")
    User queryObject(@Param("value") Long userId);
}
